﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

/// <summary>
/// Role角色类
/// </summary>
public class Role
{
    private string _roleName;
    private string _accessRight;
    public string RoleName
    {
        set { _roleName = value; }
        get { return _roleName; }
    }
    public string AccessRight
    {
        set { _accessRight = value; }
        get { return _accessRight; }
    }
	public Role()
	{
		//
		// TODO: 在此处添加构造函数逻辑
		//
	}
    public Role(string roleName,string accessRight)
    {
        this._roleName = roleName;
        this._accessRight = accessRight;
    }
    /// <summary>
    /// 新增一个角色
    /// </summary>
    /// <returns>成功返回真，否则假</returns>
    public bool AddRole()
    {
        bool seccess = false;
        string strAddRole = "insert into ROLE (ROLENAME,ACCESSRIGHT) values ("
                             +"'"+this.RoleName+"',"
                             +"'"+this.AccessRight+"')";
        DBOperation db = new DBOperation();
        seccess = db.ExcuteSql(strAddRole);
        return seccess;
    }
    /// <summary>
    /// 删除一个角色
    /// </summary>
    /// <param name="roleID">角色ID</param>
    /// <returns>成功返回真，否则假</returns>
    public static  bool DeleteRole(int roleID)
    {
        bool seccess = false;
        string strDeleteRole = "delete ROLE where ROLEID=" + roleID;
        DBOperation db = new DBOperation();
        seccess = db.ExcuteSql(strDeleteRole);
        return seccess;
    }
    /// <summary>
    /// 修改角色
    /// </summary>
    /// <param name="roleID">角色ID</param>
    /// <returns>成功返回真，否则假</returns>
    public bool UpdateRole(int roleID)
    {
        bool seccess = false;
        string strChangeRole = "update ROLE set ROLENAME='"+this.RoleName+"',"+"ACCESSRIGHT='"+this.AccessRight+"'";
        DBOperation db = new DBOperation();
        seccess = db.ExcuteSql(strChangeRole);
        return seccess;

    }
    /// <summary>
    /// 读取系统中所有的角色类型
    /// </summary>
    /// <returns>dataSet</returns>
    public DataSet FindAllRole()
    {
        DataSet ds = null;
        string strFindAllRole = "select * from ROLE";
        string tableName="Role";
        DBOperation db = new DBOperation();
        ds = db.GetDataSet(strFindAllRole, tableName);
        return ds;
    }
    /// <summary>
    /// 根据角色ID，返回角色名称
    /// </summary>
    /// <param name="roleID">角色ID</param>
    /// <returns>字符串的角色名称</returns>
    public string ReturnRoleName(int roleID)
    {
        string roleName = null;
        string strFindRoleName = "select ROLENAME where ROLEID="+roleID;
        DBOperation db = new DBOperation();
        roleName = db.ExcuteScalar(strFindRoleName).ToString();
        return roleName;
    }
}
